﻿var page = {
    FMInfoTimer: 0,

    /***************Video Panel*****************/
    videoArray: [
        { name: "As long as...", src: "as_long_as.mp4", picture: "jb1.png" },
        { name: "Purpose", src: "Purpose1.mp4", picture: "jb2.png" },
        { name: "Holy", src: "Holy.mp4", picture: "jb3.png" },
        { name: "Lonely", src: "lonely.mp4", picture: "jb4.png" },
    ],

    /* 此方法在第一次显示窗体前发生 */
    onLoad: function (event) {
        refreshDate(this);  //获取信号质量--app.js
        var that = this;
        if (fmData != 0) {
            that.FMInfoTimer = setTimeout(function () {
                that.loadAlbum();
                clearInterval(that.FMInfoTimer);
                that.FMInfoTimer = 0;
                console.log("@@setTimeout loadAlbum...  video.js");
            }, 1 * 1000)
        } else {
            that.FMInfoTimer = setInterval(function () {
                if (fmData != 0) {
                    that.loadAlbum();
                    console.log("@@setInterval loadAlbum...  video.js");
                    clearInterval(that.FMInfoTimer);
                    that.FMInfoTimer = 0;
                }
            }, 1 * 1000)
        }
        this.loadVideoList();//加载本地视频内容
    },

    /*************Music Panel*****************/
    loadAlbum: function (Class) {
        if (fmData == 0)
            return;

        var that = this;
        /***加载music list***/
        {
            var MusicList = new Array();
            for (var i = 0, len = fmData.Music.length; i < len; i++) {
                var item = new Object();
                item.albumName = new Object();
                item.albumName.value = fmData.Music[i].albumName;
                console.log("@@===========>fmData.Music[i].albumName:" + fmData.Music[i].albumName);

                var imageArr = fmData.Music[i].albumImage.split("/");
                console.log("@@===========>imageArr:" + imageArr);
                item.albumImage = new Object();
                item.albumImage.norImg = imageArr[imageArr.length - 1];//图片
                item.albumImage.customProperty = fmData.Music[i];      //MUSIC整个json
                console.log("@@===========>mp3-src:" + fmData.Music[0].albumList[0].src);
                item.albumImage.id = "Music" + i;
                MusicList.push(item);
            }
            this.setData({
                Music_list: {
                    list: {
                        page: that,
                        items: [{
                            xml: "Panels/AlbumItem",
                            items: MusicList
                        }]
                    }
                }
            });
        }
    },

    //点击专辑图片跳转--mp3界面
    onPlay: function (event) {
        audio.stop();
        pm.navigateTo({ url: "Playmp3/Playmp3", value: fmData.Music[0] });
    },

    /***************Video Panel******************/
    loadVideoList: function () {
        var videoList = new Array();
        for (var i = 0, len = this.videoArray.length; i < len; i++) {
            var videoItem = new Object();
            videoItem.label1 = { id: "videoLabel" + i, value: this.videoArray[i].name };
            videoItem.button1 = { id: "videoButton" + i };
            videoItem.imagebox1 = { value: this.videoArray[i].picture };
            videoList.push(videoItem)
        }
        this.setData({
            videoList: {
                list: {
                    page: this, 
                    items: [{
                        xml: "Panels/VideoItem", items: videoList
                    }]
                }
            }
        })
    },

    //点击播放按钮回调
    onVideoPlay: function (event) {
        var index = event.target.id.substring(11);
        console.log(index);
        audio.stop();
        console.log("index : " + index);
        console.dir(this.videoArray[index].src);
        pm.navigateTo({ url: "VideoPage/VideoPage", value: this.videoArray[index].src })
    },

    /* 此方法展示窗体后发生 */
    onResume: function (event) {

    },

    /* 当前页状态变化为显示时触发 */
    onShow: function (event) {
        currentData = this;
    },

    /* 当前页状态变化为隐藏时触发 */
    onHide: function (event) {

    },

    /* 此方法关闭窗体前发生 */
    onExit: function (event) {
        if (this.FMInfoTimer != 0) {
            clearInterval(this.FMInfoTimer);
        }
        clearInterval(this.dateTimer);
    },

    onBtn: function (event) {
        pm.navigateBack();
    },
};

Page(page);

page = 0;
